import { Component, OnInit, ViewChild ,ChangeDetectorRef,} from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { Body, _HttpClient } from '@delon/theme';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { STData } from '@delon/abc';

@Component({
  selector: 'app-card-charge-list',
  templateUrl: './card-charge-list.component.html',
  styles: []
})
export class CardChargeListComponent implements OnInit {
  @ViewChild('st', { static: false }) st: TablePageComponent;
  showTable=false;
  loading = false;
  radioValue = 'A';
  selectData: any;
  config: SPage = {
    columns: [
      {
        index: 'cardCode',
        title: '卡编号',
        width:100,
        type:ColumnType.tag,
        filter: {
          items:[],
          index:'name2',
          placeholder: '请输入小区名称',
          type: 'select',
        }
      },
      {
        index: 'cardType',
        title: '卡类型',
        type: ColumnType.tag,
        tag: {
          1:{text:'IC卡'},
          2:{text:'CPU卡'},
          3:{text:'身份证'},
          4:{text:'居住证'},
          5:{text:'银行卡'},
          6:{text:'APP'},
        },
        filter: {
          index:'name3',
          placeholder: '请输入地址',
          type: 'string'
        }
      },
      {
        index: 'cardCategory',
        title: '卡属性',
        type: ColumnType.tag,
        tag:{
          1:{text:'房东卡'},
          2:{text:'租户卡'},
        },
        filter: {
          placeholder: '请输入卡编号',
          type: 'string'
        }
      },
      {
        index: 'cardStatus',
        title: '状态',
        type: ColumnType.tag,
        tag:{
          0:{text:'未激活',color: 'red'},
          1:{text:'已激活', color: 'green'},
          2:{text:'丢失', color: 'red'},
          3:{text:'损坏', color: 'red'},
          4:{text:'冻结', color: 'red'},
          5:{text:'待缴费', color: 'red'},
          6:{text:'已过期', color: 'red'},
          7:{text:'退卡', color: 'red'},
          9:{text:'其他'}
        },
        filter: {
          index:'startTime',
          placeholder: '到期时间(起)',
          type: 'date'
        }
      },
      {
        index: 'infoName',
        title: '持卡人',
        filter: {
          index:'endTime',
          placeholder: '到期时间(止)',
          type: 'date'
        }
      },
      {
        index: 'infoMobile',
        title: '持卡人手机号',
        filter: {
          index:'infoName',
          placeholder: '持卡人',
          type: 'string'
        }
      },
      {
        index: 'houseName',
        title: '详细地址',
        filter: {
          index:'name9',
          placeholder: '卡类型',
          type: 'string'
        }
      },
      {
        index: 'cardUsingEndTime',
        title: '到期时间',
        width:150
      },
      {
        index: '',
        title: '缴费时间',
        type:ColumnType.tag,
        filter: {
          index:'name11',
          placeholder: '居住类别',
          type: 'select',
          items: [
            {label: '房东', value: true},
            {label: '租客', value: false},
          ]
        }
      },
      {
        index: 'mark',
        title: '备注',
        type:ColumnType.tag,
        filter: {
          index:'cardStatus',
          placeholder: '状态',
          type: 'select',
          items: [
            {label: '快到期', value: 0},
            {label: '待缴费', value: 1},
            {label: '已过期', value: 2},
          ]
        }
      },
      {
        index: 'status',
        title: '状态',
        type: ColumnType.tag,
        tag:{
         // 0:{text:'未激活',color: 'red'},
        },
      }
    ],
    showCheckBox: true,
    reqUrl:this.api.doorCard.queryPeopleCardInfo.url,
    defaultParam:{carType:this.radioValue}
    // editBtn: [
    //   // { title: '审批' }
    //   {title : '门禁权限'}
    // ]
  }

  constructor(private http: _HttpClient,  private api: ApiService, private modal: NzModalService, private message: NzMessageService, private ref: ChangeDetectorRef,) { }
  ngOnInit() {
    this.feachCommunity();
  }
  _console(e: any): void {
    this.selectData = e;
  }
  dataProcess(data){
    return data;
  }

  radioChange(e):void{
    this.radioValue=e;
    let res=this.st.sf.value;
    this.config.defaultParam={carType:e};
    this.st.st.reset({carType:e,...res});
  }
  //删除卡号后面的8个0
  delCardZero(num:string):string{
    if(num.length > 8){
      num = num.substring(0,num.length - 8);
    }
    return num;
  }
    //获取小区下拉框数据
    feachCommunity(){
      this.http.post(this.api.area.list.url, {areaName: ''}).subscribe((res: any) => {
       if (res.status == '200') {
         this.config.columns[0].filter.items= res.data.map(item => {
           return {
             label: item.areaName,
             value: item.id
           }
         });
         this.showTable=true;
       }
     })
   }

   //导出
   export(){
    this.loading=true;
    let body:any={};
    if(this.st.st.req.params != undefined){
      body=this.st.st.req.params;
    }
    body.pageNum=1;
    body.pageSize=this.st.st.total;
    this.http.post(this.api.doorCard.queryPeopleCardInfo.url,body).subscribe(res => {
      this.loading=false;
      if(res.status == 200 && res.data.list.length > 0){
        let data=res.data.list;
         this.st.st.export(data,{
          filename : "门卡缴费.xlsx"
        })
      }else{
        this.message.error(res.message);
      }
    })
  

  }



}
